package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsGridProcessGroup;
import com.econ.powercloud.ems.dal.mapper.EmsGridProcessGroupMapper;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author jwc
 * @since 2022/08/26
 */
@Repository
public class EmsGridProcessGroupDAO extends ServiceImpl<EmsGridProcessGroupMapper, EmsGridProcessGroup> {

    public EmsGridProcessGroup selectByStationIdAndTypeAndOrderNum(String energyStationId, Integer type, Integer orderNum) {
        LambdaQueryWrapper<EmsGridProcessGroup> wrapper = Wrappers.<EmsGridProcessGroup>lambdaQuery()
                .eq(EmsGridProcessGroup::getEnergyStationId, energyStationId)
                .eq(EmsGridProcessGroup::getType, type)
                .eq(EmsGridProcessGroup::getOrderNum, orderNum);
        return this.baseMapper.selectOne(wrapper);
    }

    public List<EmsGridProcessGroup> selectGroupByStationId() {
        LambdaQueryWrapper<EmsGridProcessGroup> wrapper = Wrappers.<EmsGridProcessGroup>lambdaQuery()
                .groupBy(EmsGridProcessGroup::getEnergyStationId)
                .select(EmsGridProcessGroup::getEnergyStationId);
        return this.baseMapper.selectList(wrapper);
    }
}
